package chain;

import java.util.ArrayList;
import java.util.List;

/**
 * @name AlgorithmDemo2
 * @class name：PACKAGE_NAME
 * @class describe
 * @anthor Jackfruit
 * @time 2020/8/31 20:44
 * @change
 * @changTime
 */
public class ChainManager implements IBaseTask {
  private List< IBaseTask > mList;
  private int index = 0;

  public void addIBaseTasg(IBaseTask task) {
    if (mList == null) {
      mList = new ArrayList<>();
    }
    mList.add(task);
  }

  @Override
  public void doNation(boolean isTask, IBaseTask task) {
    if (isTask || mList.isEmpty() || index > mList.size() - 1) {
      index = 0;
      return;
    }
    IBaseTask iBaseTask = mList.get(index);
    index++;
    iBaseTask.doNation(isTask, task);
  }
}
